package com.wdd.myplatform.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.wdd.myplatform.entity.MongoTest;
import com.wdd.myplatform.service.MongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wdd
 */
@RestController
@RequestMapping("/mongoController")
public class MongoController {

    @Autowired
    private MongoService mongoService;

    @GetMapping(value = "/saveTest")
    public void saveTest() throws Exception {
        MongoTest mgtest = new MongoTest();
        mgtest.setId(IdWorker.getIdStr());
        mgtest.setAge(33);
        mgtest.setName("ceshi");
        mongoService.saveTest(mgtest);
    }

    @GetMapping(value = "/findTestByName")
    public MongoTest findTestByName() throws Exception {
        MongoTest mongoTest = mongoService.findTestByName("ceshi");
        return mongoTest;
    }

    @GetMapping(value = "/deleteTestById")
    void deleteTestById(Integer id) throws Exception {
        mongoService.deleteTestById(id);
    }
}
